package com.xrj4j.car_news.utils

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitUtils {

    private var retrofit: Retrofit? = null

    private fun getRetrofit(baseUrl: String): Retrofit {
        if (retrofit == null) {
            retrofit = Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        }
        return retrofit!!
    }


    fun <T> getApi(baseUrl: String, clazz: Class<T>): T {
        val retrofit = getRetrofit(baseUrl)
        return retrofit.create(clazz)
    }

}